$(function(){
	var server = "https://cloud.kaaction.com";
	var host = server + "/crab/api/v1/";
	var cardpas = sessionStorage['cardpassword'] ;
	var cardn = sessionStorage['cardnumber'] ;
	var cardnum = '';
	var resinfo = '';
	var resinfomation = '';
	var statusnumber = '';
	var iframewidth = $(window).width();
	console.log(cardn)
	console.log(cardpas)
	$.ajax({
		url:host + 'crabProductApi/selRecommendProduct',
		dataType:'json',
		async:false,
		data:{
			cardNum:cardn,
			password:cardpas
		},
		success:function(res){
			console.log(res);
			cardnum = res.data.useState;
			resinfomation = res.data;
			// 未使用状态
			if(cardnum == 0){
				$('.change').removeClass('show');
				$('.recommend').removeClass('show');
				$('span.usercard').html(resinfomation.cardNum);
				$('span.userpaasword').html(resinfomation.password);
				$('span.userstatus').html('未使用');
				getRecomProduct();
			}else{
				// 使用已发货
				if(res.data.state == 1){	
					userInfo();	
					$('.send').removeClass('show');
					$('span.userstatus').html('已发货/已完成');					
					$('span.express-name').html(resinfomation.expressCompany);
					$('span.express-num').html(resinfomation.expressNum);
					// 获取屏幕宽度		
					$('#kd').attr('width',iframewidth);
					$('iframe').attr('src',resinfomation.logisticsInformationUrl);
				}else{
					$('.recommend').removeClass('show');
					$('span.userstatus').html('未发货');
					userInfo();
					getRecomProduct();
				}
			}
		}
	})
	function userInfo(){
		$('.unsend').removeClass('show');
		$('span.usercard').html(resinfomation.cardNum);
		$('span.userpaasword').html(resinfomation.password);
		$('span.username').html(resinfomation.name);
		$('span.usertel').html(resinfomation.mobile);
		$('span.useraddress').html(resinfomation.address);
		var datw = new Date(resinfomation.hopeDate);
		var year=datw.getFullYear(); 
		var month=datw.getMonth()+1; 
		var date=datw.getDate(); 
		var wantdate = year+"-"+month+"-"+date; 
		$('span.usersendtime').html(wantdate);
		$('span.usernote').html(resinfomation.remarks);
	}
	function getRecomProduct(){
		$.each(resinfomation.listRecommendProduct,function(key,value){
			var $alink  = $('<a>');
			$alink.attr('href',value['link']);
			var $div = $('<div>');
			var $divcrab = $('<div>');
			$alink.addClass('tocarb');
			$div.addClass('carb-content');
			$divcrab.addClass('carb-des');
			$alink.href = value['link'];
			$divcrab.append('<p>'+ value['name'] +'</p>')
					.append('<p>'+ value['male'] +'</p>')
					.append('<p>'+ value['female'] +'</p>')
			$div.append('<img src='+server + value['photo'] +'></img>')
				.append($divcrab)
				.appendTo($alink);
			$alink.appendTo('div.crablist');
		})
	}
})




